package cn.tedu.medicalappointmentsystemk.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Slf4j
@Configuration
public class SpringMVCConfig implements WebMvcConfigurer {
    public SpringMVCConfig(){
        log.debug("创建配置类对象：SpringMvcConfig");
    }

    @Override
    public void addCorsMappings(CorsRegistry registry){
        registry.addMapping("/**")
                .allowedHeaders("*") //带任意请求头都允许访问
                .allowedMethods("*")    //任意请求方式都允许访问 get/post/put/delete
                .allowedOriginPatterns("*") //任意主机地址和端口号都允许访问
                .allowCredentials(true)  //允许携带cookie/session信息
                .maxAge(3600);       //一个小时内同一请求直接放行
    }
}
